package classes;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;

public class OrderWriteToFile 
{
	
	public void outputWriteToFile(String itemDetails) // item details gotten from orderBean as a long string separated with '/' 
	{
		try 
		(
			// new file to write to, (true - lets you to append)
			BufferedWriter bufOutPut = new BufferedWriter(new FileWriter("D:/OrderDetails.csv", true))
		)
		{
			// split all itemDetails from the slashes and put them into an array
			String[] itemDetailsArray = itemDetails.split("/");
			
			// loop through array and write the details line by line
			for(String item : itemDetailsArray)
			{
				bufOutPut.write(item);
				bufOutPut.newLine();
		    }
		}
		
		catch(FileNotFoundException fnfe)
		{
			System.out.println(fnfe.getMessage());
		}
		catch(IOException ioe)
		{
			System.out.println("Exception:" + ioe);
		}
	}
	
}
